-module(test1_game_data).

-export([known_games/0, known_figures/0]).

visual_to_moves(Str) -> test1_game:visual_to_moves(Str).

known_games() ->
    Moves1 = visual_to_moves("
Aabcde
.ED
.BC
    "),
    Moves2 = visual_to_moves("
Aabdef
BD
CE
cF
    "),
    Moves3 = visual_to_moves("
aBCDE
b
c  A
d
e
    "),
    Moves4 = visual_to_moves("
a
b  BCDE
c  A
d
e
    "),
    Moves5 = visual_to_moves("
ABCc
aDEF
 b
  d
   e
    f
"),
    Moves6 = visual_to_moves("
Aabdef
 BD
  CEF
   c
"),

Moves7=[{x,8,8,o,8,10},
               {x,9,10,o,9,11},
               {x,10,10,o,10,12},
               {x,11,10,o,11,13},
               {x,12,10,o,7,9}],
Moves8 = [{x,8,8,o,8,10},
               {x,9,10,o,9,11},
               {x,10,10,o,10,12},
               {x,11,10,o,7,9},
               {x,12,10,o,11,13}],
    Res = [Moves1, Moves2, Moves3, Moves4, Moves5, Moves6, Moves7, Moves8,

[{x,8,8,o,8,9},
           {x,8,7,o,9,8},
           {x,8,6,o,10,7},
           {x,8,5,o,8,4},
           {x,11,6,o,7,10},
           {x,6,11,o,9,10},
           {x,7,8,o,10,11},
           {x,6,8,o,11,12},
           {x,5,8,o,12,13}],

[{x,8,8,o,9,8},
               {x,7,8,o,8,9},
               {x,6,8,o,7,10},
               {x,5,8,o,4,8},
               {x,10,7,o,6,11},
               {x,5,12,o,6,10},
               {x,8,7,o,5,9},
               {x,8,6,o,7,11},
               {x,8,5,o,8,4},
               {x,9,6,o,8,12}],

[{x,8,8,o,7,8},{x,9,8,o,8,9},{x,10,8,o,9,10},{x,11,8,o,12,8},{x,10,11,o,6,7},{x,5,6,o,11,9},{x,11,7,o,10,10},{x,11,6,o,9,11},{x,11,5,o,8,12}],
[{x,8,8,o,9,9},{x,10,9,o,8,10},{x,11,9,o,10,8},{x,12,9,o,7,11},{x,13,9,o,14,9},{x,11,7,o,6,12}],
[{x,8,8,o,10,10},{x,11,10,o,9,11},{x,12,10,o,11,9},{x,13,10,o,8,12},{x,14,10,o,7,13}],
[{x,8,8,o,7,9},{x,8,9,o,8,10},{x,8,7,o,9,11},{x,8,6,o,8,5},{x,10,12,o,6,7},{x,6,8,o,7,6},{x,9,4,o,5,8},{x,4,9,o,7,8},{x,9,9,o,7,7},{x,10,10,o,7,10}],
[{x,8,8,o,8,10},{x,8,7,o,9,9},{x,8,9,o,10,8},{x,8,6,o,8,5},{x,11,7,o,6,7},{x,7,11,o,7,6},{x,9,4,o,7,9},{x,5,8,o,6,8},{x,9,11,o,6,10},{x,5,7,o,7,10},{x,9,10,o,6,9},{x,9,12,o,6,11}],
[{x,8,8,o,9,9},{x,9,7,o,10,8},{x,10,6,o,7,9},{x,11,5,o,12,4},{x,10,9,o,6,8},{x,6,9,o,8,10},{x,11,7,o,9,12},{x,12,8,o,7,11},{x,13,9,o,6,12}],
[{x,8,8,o,8,10},{x,9,9,o,9,11},{x,10,10,o,11,11},{x,7,7,o,6,6},{x,12,11,o,7,9},{x,10,12,o,6,8},{x,5,7,o,8,11},{x,6,9,o,10,11},{x,7,11,o,8,12},{x,8,9,o,6,7},{x,10,9,o,6,5},{x,11,9,o,6,4}],
[{x,8,8,o,6,9},{x,9,9,o,11,11},{x,10,10,o,7,11},{x,7,7,o,6,6},{x,11,9,o,6,8},{x,12,8,o,6,7},{x,6,10,o,6,5}],
[{x,8,8,o,6,10},{x,9,9,o,6,8},{x,10,10,o,7,7},{x,11,11,o,12,12},{x,12,10,o,6,7},{x,13,9,o,6,9},{x,6,11,o,6,6}]
[{x,8,8,o,7,11},{x,7,8,o,9,11},{x,9,8,o,10,8},{x,6,8,o,5,8},{x,8,11,o,10,11},{x,8,10,o,8,9},{x,8,12,o,10,12},{x,8,13,o,8,14},{x,8,7,o,10,10},{x,8,6,o,10,9}],
[{x,8,8,o,6,11},{x,9,8,o,6,8},{x,10,8,o,11,8},{x,7,8,o,6,9},{x,6,10,o,9,11},{x,6,7,o,10,11},{x,8,9,o,8,11},{x,7,11,o,5,6},{x,9,10,o,11,11},{x,12,11,o,11,10},{x,11,9,o,5,8},{x,10,9,o,7,10},{x,9,9,o,9,12}],
[{x,8,8,o,7,10},{x,7,8,o,9,10},{x,8,10,o,5,8},{x,9,8,o,6,8},{x,10,8,o,11,8},{x,9,9,o,7,11},{x,11,7,o,12,6},{x,9,7,o,8,11},{x,9,6,o,9,5},{x,8,7,o,6,9},{x,8,9,o,9,12}],
[{x,8,8,o,6,10},{x,9,9,o,6,8},{x,10,10,o,7,7},{x,11,11,o,12,12},{x,6,9,o,7,9},{x,9,8,o,7,10},{x,7,8,o,8,10},{x,10,8,o,11,8},{x,5,10,o,9,11},{x,10,12,o,5,7}],
[{x,8,8,o,6,9},{x,8,9,o,6,7},{x,8,7,o,8,6},{x,8,10,o,8,11},{x,6,8,o,5,8},{x,7,9,o,7,10},{x,9,12,o,4,7}],
[{x,8,8,o,6,10},{x,9,9,o,6,8},{x,10,10,o,7,7},{x,11,11,o,12,12},{x,9,10,o,6,7},{x,6,9,o,4,10},{x,8,10,o,5,9},{x,8,6,o,3,11}],
[{x,8,8,o,6,10},{x,9,9,o,6,7},{x,10,10,o,7,7},{x,11,11,o,12,12},{x,9,10,o,6,8},{x,6,9,o,9,5},{x,8,10,o,8,6},{x,10,4,o,5,9}]

[{x,8,8,o,9,9},{x,9,7,o,11,9},{x,10,6,o,7,9},{x,11,5,o,12,4},{x,12,6,o,10,9},{x,13,7,o,8,9}]
    ],
    Res.

known_figures() ->
%    Figs = [ [{0,1},{0,2},{0,3}], [{0,1},{0,2},{0,3},{0,4}], [{0,1},{0,2},{0,3},{0,4},{0,5}],
%            [{1,1},{2,2},{3,3}], [{1,1},{2,2},{3,3},{4,4}], [{1,1},{2,2},{3,3},{4,4},{5,5}] ],

    F = "
*xxx
===
*xxxx
===
x*xxx
===
xx*xx
===
*xxxxx
===
*
 x
  x
   x
===
*
 x
  x
   x
    x
===
x
 x
  *
   x
    x
===
x
 *
  x
   x
    x
===
*
 x
  x
   x
    x
     x
===
 x
x*xxxx
 x
 x
 x
 x
",
[ fig_img_parse(string:tokens(FTxt,"\n\r")) || FTxt <- string:tokens(F,"=") ].


fig_img_parse(Lines) ->
    Xpos = fig_img_ch_coords(Lines,$x),
    [{PointX,PointY}] = fig_img_ch_coords(Lines,$*),
    [ {X-PointX,Y-PointY} || {X,Y} <- Xpos ].

fig_img_ch_coords(Lines,Char) ->
    lists:flatten([ fig_img_ch_coords(Line,Char,Y) ||  {Line,Y} <- lists:zip(Lines, lists:seq(1,length(Lines))) ]).

fig_img_ch_coords(Line,Char,Y) ->
    Zipped = lists:zip(Line,lists:seq(1,length(Line))),
    %io:format("Zipped ~p ~p~n",[Zipped,Char]),
    [ {X,Y} || {Ch,X} <- Zipped, Ch =:= Char ].
